package stubs;

import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;

import objetos.ClienteObj;
import interfaces.Cliente;

public class ClienteStub implements Cliente {

	@Override
	public boolean atualizarDadosCliente(ClienteObj cliente) {
		try {
			// Cria Endpoint para envio do xml
			EndpointReference targetEPR = new EndpointReference(Bind.getServicesLocation() + "Cliente/atualizarDadosCliente");
			
			// Cria o arquivo xml
			OMElement payload = cliente.toOMElement();
			
			// Cria servico do cliente
			ServiceClient sc = new ServiceClient();
			
			// Cria opcoes do servico
			Options opt = new Options();
			opt.setTo(targetEPR);
			sc.setOptions(opt);
			
			// Envia e recebe resposta
			OMElement res;
			
			res = sc.sendReceive(payload);
			
			return Boolean.parseBoolean(res.getText());
			
		} catch (AxisFault e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return false;
	}

	@Override
	public boolean efetuarCadastro(ClienteObj cliente) {
		try {
			// Cria Endpoint para envio do xml
			EndpointReference targetEPR = new EndpointReference(Bind.getServicesLocation() + "Cliente/efetuarCadastro");
			
			// Cria o arquivo xml
			OMElement payload = cliente.toOMElement();
			
			// Cria servico do cliente
			ServiceClient sc = new ServiceClient();
			
			// Cria opcoes do servico
			Options opt = new Options();
			opt.setTo(targetEPR);
			sc.setOptions(opt);
			
			// Envia e recebe resposta
			OMElement res;
			
			res = sc.sendReceive(payload);
			
			return Boolean.parseBoolean(res.getText());
			
		} catch (AxisFault e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return false;
	}

	@Override
	public boolean efetuarLogin(String login, String senha) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void efetuarLogout() {
		// TODO Auto-generated method stub
		
	}

}
